home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / pyshared / softwareproperties / AptAuth.py < prev    next >
Text File  |  2008-10-15  |  3KB  |  80 lines

  1. # dialog_apt_key.py.in - edit the apt keys
  2. #  
  3. #  Copyright (c) 2004 Canonical
  4. #  
  5. #  Author: Michael Vogt <mvo@debian.org>
  6. #  This program is free software; you can redistribute it and/or 
  7. #  modify it under the terms of the GNU General Public License as 
  8. #  published by the Free Software Foundation; either version 2 of the
  9. #  License, or (at your option) any later version.
  10. #  This program is distributed in the hope that it will be useful,
  11. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #  GNU General Public License for more details.
  14. #  You should have received a copy of the GNU General Public License
  15. #  along with this program; if not, write to the Free Software
  16. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. #  USA
  18.  
  19. import os
  20. import subprocess
  21. import gettext
  22. from subprocess import PIPE
  23.  
  24. # gettext convenient
  25. _ = gettext.gettext
  26. def dummy(e): return e
  27. N_ = dummy
  28.  
  29. # some known keys
  30. N_("Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>")
  31. N_("Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>")
  32.  
  33. class AptAuth:
  34.     def __init__(self):
  35.         self.gpg = ["/usr/bin/gpg"]
  36.         self.base_opt = self.gpg + ["--no-options", "--no-default-keyring",
  37.                                     "--secret-keyring", "/etc/apt/secring.gpg",
  38.                                     "--trustdb-name", "/etc/apt/trustdb.gpg",
  39.                                     "--keyring", "/etc/apt/trusted.gpg"]
  40.         self.list_opt = self.base_opt + ["--with-colons", "--batch",
  41.                                          "--list-keys"]
  42.         self.rm_opt = self.base_opt + ["--quiet", "--batch",
  43.                                        "--delete-key", "--yes"]
  44.         self.add_opt = self.base_opt + ["--quiet", "--batch",
  45.                                         "--import"]
  46.         
  47.        
  48.     def list(self):
  49.         res = []
  50.         #print self.list_opt
  51.         p = subprocess.Popen(self.list_opt,stdout=PIPE).stdout
  52.         for line in p.readlines():
  53.             fields = line.split(":")
  54.             if fields[0] == "pub":
  55.                 name = fields[9]
  56.                 res.append("%s %s\n%s" %((fields[4])[-8:],fields[5], _(name)))
  57.         return res
  58.  
  59.     def add(self, filename):
  60.         #print "request to add " + filename
  61.         cmd = self.add_opt[:]
  62.         cmd.append(filename)
  63.         p = subprocess.Popen(cmd)
  64.         return (p.wait() == 0)
  65.         
  66.     def update(self):
  67.         cmd = ["/usr/bin/apt-key", "update"]
  68.         p = subprocess.Popen(cmd)
  69.         return (p.wait() == 0)
  70.  
  71.     def rm(self, key):
  72.         #print "request to remove " + key
  73.         cmd = self.rm_opt[:]
  74.         cmd.append(key)
  75.         p = subprocess.Popen(cmd)
  76.         return (p.wait() == 0)
  77.